using TMPro;
using UnityEngine;

namespace Super
{
	[ExecuteInEditMode]
	[RequireComponent(typeof(TextMeshProUGUI))]
	public class Lang : MonoBehaviour, ILangRefresh
	{
		public string key = "";

		[Button("OnDirtyRefresh", 150)]
		public string btn = "添加多语言并刷新文本";

		public void OnEnable()
		{
			OnLangRefresh();
		}

		public void OnDirtyRefresh()
		{
			bool isAdd = LangManager.TryAddCustomKey(key);
			string stateStr;
			if (isAdd)
			{
				stateStr = $"<color=#{ColorUtility.ToHtmlStringRGB(Color.green)}>添加至：</color>";
			}
			else
			{
				stateStr = $"<color=#{ColorUtility.ToHtmlStringRGB(Color.red)}>已存在：</color>";
			}

			LogUtil.Log(LogType.Normal, LogCategory.Lang, $"\"{key}\"{stateStr}{FWConfig.customLangKeyPath}文件中");
			transform.SetTMPUGUIByKey("", key);
		}

		public void OnLangRefresh()
		{
			transform.SetTMPUGUIByKey("", key);
		}
	}
}


